﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;

namespace TestApp.ViewModels
{
    public partial class Windows2ViewModel : ObservableObject
    {
        // 自动生成可绑定属性：TextContent + OnPropertyChanged
        [ObservableProperty]
        private string textContent = "初始内容";

        // 自动生成 ICommand 属性：UpdateTextCommand
        [RelayCommand]
        private void UpdateText()
        {
            TextContent = "通过 Toolkit 命令更新的内容";
        }

        public ICommand EnterKeyCommand { get; }

        public Windows2ViewModel()
        {
            EnterKeyCommand = new RelayCommand<object>(OnEnterPressed!);
        }

        private void OnEnterPressed(object param)
        {
            Trace.WriteLine(param);
            if (param is not null)
                MessageBox.Show(param.ToString());
        }
    }
}
